Next | Prev | Up | Top | Contents | Index

Linking Multilanguage Programs

The source language of the main program may differ from that of a subprogram. In this case, you can link multilanguage programs.

Follow the steps below to link multilanguage programs. (Refer to Figure 2-1 for an illustration of the process.)

  1. Compile object files from the source files of each language separately by using the -c option.

    For example, if the source consists of a Fortran main program (main.f) and two files of C functions (more.c and rest.c), use the commands:

    cc -c more.c rest.c

    f77 -c main.f

    These commands produce the object files main.o, more.o, and rest.o.

  2. Use the compiler associated with the language of the main program to link the objects:

    f77 main.o more.o rest.o

    The compiler drivers supply the default set of libraries necessary to produce an executable from the source of the associated language. However, when producing executables from source code in several languages, you may need to specify the default libraries explicitly for one or more of the languages used. For instructions on specifying libraries, see "Linking Libraries."

Figure 2-1 : Compilation Control Flow for Multilanguage Programs

Note: Use caution when passing pointers and longs between languages as some languages use different type sizes and structures for data types. For specific details about compiling multilanguage programs, refer to the programming guides for the appropriate languages.


Next | Prev | Up | Top | Contents | Index